import os


def merge_audio_file(files, dest_path):
    cmd = 'ffmpeg -i "concat:{}" -codec copy "{}"'  # 管道命令
    command = cmd.format('|'.join(files), dest_path)
    os.system(command)
    for file1 in files:
        os.remove(file1)


if __name__ == "__main__":
    dir_str = 'C:\\ai\\data\\tts'
    for root, dirs, filess in os.walk(dir_str):
        flst = []
        for file in filess:
            flst.append(dir_str + '/' + file)
        merge_audio_file(flst, 'C:\\ai\\data\\tts\\all.mp3')
